 <?php

 class district{

	/**
	 * 将拼音转为地区id
	 * @param int $name
	 * @return int
	*/
	public static function pinyinTodisId($name){
		$reuslt = mysql::connect()->fetch_all("select dis_id from district where name='{$name}'");
		return $reuslt[0];
	}
	/**
     * 显示所有地区
     * @return array
     */
    public static function getDistrict(){
        return mysql::connect()->fetch_all("select * from district ORDER BY `id` ASC");
    }
	/**
     * 执行修改
     * @return array
     */
	public static function district_edit($_post){
		$name = trim($_post['name']);
		$sql = "UPDATE `district` SET `name` = '$name' where id=$_post[id]";
		mysql::connect()->query($sql);
		k::message('修改成功','?action=district-list');
	}
	/**
	 * 删除
	 * @param mixed $id
	*/
	public static function district_del($id){
		$sql = "DELETE FROM district WHERE id=$id";
		mysql::connect()->query($sql);
		k::message('这条district已删除成功','javascript:history.go(-1);');
	}
	/**
	 * 添加
	 * @param string $_post
	*/
	public static function district_add($_post){
		if($_post['name']==''){
			k::message('名儿呢？','javascript:history.go(-1);');
		}
		$sql = "INSERT INTO district values('','{$_post[name]}')";
		mysql::connect()->query($sql);
		k::message('成功添加!','javascript:history.go(-1);');
	}
 }